package com.example.concurrency.exercise;

/**
 * @author: dangwen
 * @createDate: 2021/2/5
 */
public class CommonThread implements Runnable{

    int num = 0;

//    static class CommonThread01 implements Runnable{
//        @Override
//        public void run() {
//            num++;
//            System.out.println(num);
//        }
//    }
//
//    static class CommonThread02 implements Runnable{
//        @Override
//        public void run() {
//            num++;
//            System.out.println(num);
//        }
//    }

    public static void main(String[] args) {
        CommonThread commonThread = new CommonThread();
        for (int i = 0; i < 50; i++) {
//            new Thread(new CommonThread01()).start();
//            new Thread(new CommonThread02()).start();
            new Thread(commonThread).start();
        }
    }

    @Override
    public void run() {
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        num++;
        System.out.println(Thread.currentThread().getName()+" work " + num);
    }
}
